package com.scsj.supermarket.adapter;

import com.scsj.supermarket.base.QueryShopInTradeBase;
import com.scsj.supermarket.bean.QueryShopInTradeBean;
import com.scsj.supermarket.model.BaseModel;

import dkmvp.net.ResponseCallback;
import dkmvp.net.ResponseHandler;
import dkmvp.net.RetryWithDelay;
import okhttp3.RequestBody;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 修改支付密码Model
 */

public class QueryShopInTradeModel extends BaseModel implements QueryShopInTradeBase.IModel {

    @Override
    public Subscription getData(RequestBody requestBody, final ResponseCallback<QueryShopInTradeBean> callback) {
        Observable<QueryShopInTradeBean> observable = service.queryShopInTrade(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<QueryShopInTradeBean>() {
                    @Override
                    public void call(QueryShopInTradeBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }
}
